﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows.Forms;

namespace WinFormAutoUpdateDemo
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            try
            {

                HttpHelper hh = new HttpHelper();
                var dic = hh.CompareLocalAndRemoteFiles();
                if (dic.Count > 0)
                {
                    if (MessageBox.Show("检测到新版本,您要现在更新吗?", "更新提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        if (System.Diagnostics.Process.GetProcessesByName(hh.StartUp.Split('.')[0]).ToList().Count > 0)
                        {
                            MessageBox.Show("程序已经运行");
                            Application.Exit();
                        }
                        else
                        {
                            Application.EnableVisualStyles();
                            Application.SetCompatibleTextRenderingDefault(false);
                            Application.Run(new Form1());
                        }
                    }
                    else
                    {
                        Process.Start(hh.StartUp);
                    }
                }
                else
                {
                    Process.Start(hh.StartUp);
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
